#!/usr/bin/python
# encoding: utf-8
'''
@File    :   code.py
@Time    :   2020/03/11 21:54:19
@Author  :   fangkaijin 
@Version :   1.0
@Contact :   fangkaijin@gmail.com
@License :   杭州移动互联
@Desc    :   查询接口数据
'''

# 导入库包

import sys, os
from urllib3 import PoolManager
import json
import time

#线下
localUrl = 'https://testes.meishubao.com/api/device/getlog'
#线上
originUrl = 'https://onlineesapi.meishubao.com/api/device/getlog'

manager = PoolManager(10)

logInfos = []

def seacheData(type, map):
    if 1 == type:
        res = manager.request('POST', originUrl, fields=map)
    elif 2 == type:
        res = manager.request('POST', localUrl, fields=map)
    else:
        res = manager.request('POST', localUrl, fields=map)
    json.loads(res.data, object_hook=json2LogInfo)
    return logInfos

class LogInfo(object):
    def __init__(self, id, roomid, uid, otheruid, build, deviceName, type, idfa, system, logtype, logurl, logtime, proType, status, ctime):
        self.id = id
        self.roomid = roomid
        self.uid = uid
        self.otheruid = otheruid
        self.build = build
        self.deviceName = deviceName
        self.type = type
        self.idfa = idfa
        self.system = system
        self.logtype = logtype
        self.logurl = logurl
        self.logtime = logtime
        self.proType = proType
        self.status = status
        self.ctime = ctime

def json2LogInfo(json):
    if json.get('data') is None:
        lf = LogInfo(json.get('id'),
                     json.get('roomid'),
                     json.get('uid'),
                     json.get('otheruid'),
                     json.get('build'),
                     json.get('deviceName'),
                     json.get('type'),
                     json.get('idfa'),
                     json.get('system'),
                     json.get('logtype'),
                     json.get('logurl'),
                     json.get('logtime'),
                     json.get('proType'),
                     json.get('status'),
                     json.get('ctime'))
        logInfos.append(lf)


if __name__ == '__main__':
     ls = seacheData(2, {'logtype':2,
                         'uid':'',
                         'otheruid':'',
                         'idfa':'',
                         'roomid':'689184604042839104',
                         'build':'',
                         'devices_name':'',
                         'devicetype':'',
                         'sys':'',
                         'starttime':1585719911,
                         'endtime':1586414101})
     for l in ls:
         print(l.roomid)
